package com.atguigu.gmall.common.config.minio.configDemo2;

import com.atguigu.gmall.common.config.minio.properties.MinioProperties;
import io.minio.MinioClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class MinioConfiguration {
    //创佳Minio客户端
    @Bean
    public MinioClient  minioClient(MinioProperties minioProperties) throws Exception {
        MinioClient minioClient =new MinioClient(minioProperties.getEndpoint(),
                minioProperties.getAccessKey(),
                minioProperties.getSecretKey());
        boolean exists = minioClient.bucketExists(minioProperties.getBucketName());
        //如果bucket不存在 就要创建
        if(!exists){
             minioClient.makeBucket(minioProperties.getBucketName());
        }
        return  minioClient;
    }
}
